package client;

import event.Event;
import event.EventHandler;

public class ServerHostNameEventHandler implements EventHandler {

	private final ClientController mController;

	public ServerHostNameEventHandler(ClientController controller) {
		mController = controller;
	}

	@Override
	public void handle(Event e) {
		if (e.type == Event.HOST_TYPE) {
			String[] split = e.parameters.split("DELIMETER");
			if (split.length == 2) {
				String hostname = split[0];
				String file = split[1];

				DownloadManager manager = mController.getDownloadManager();

				Download download = manager.getDownload(file);
				if (download == null) {
					download = new Download(hostname, file, "");
					manager.addDownload(download);
				}

				if (download.isPaused()) {
					manager.download(download);
				}
			}
		}
	}
}
